﻿using System;
using System.Reflection;

namespace CDude.Vita
{
    internal partial class VitaCOM
    {
        private static void help()
        {
            Console.WriteLine("{0} - Connect to a device.", Tabs("CONNECT", 13));
            Console.WriteLine("{0} - Display detailed information about a device.", Tabs("DETAILS", 13));
            Console.WriteLine("{0} - Disconnect from the connected device.", Tabs("DISCONNECT", 13));
            Console.WriteLine("{0} - Exit VitaCOM.", Tabs("EXIT", 13));
            Console.WriteLine("{0} - Display a list of commands.", Tabs("HELP", 13));
            Console.WriteLine("{0} - Kill the PSM app on the connected device.", Tabs("KILL", 13));
            Console.WriteLine("{0} - Launch an application on the connected device.", Tabs("LAUNCH", 13));
            Console.WriteLine("{0} - Display a list of devices.", Tabs("LIST", 13));
            Console.WriteLine("{0} - Pack a folder into a .PSMPAC file.", Tabs("PACK", 13));
            Console.WriteLine("{0} - Uninstall an application from the connected device.", Tabs("UNINSTALL", 13));
            Console.WriteLine("{0} - Upload and install an application to the connected device.", Tabs("UPLOAD", 13));
        }

        private static void help(string command)
        {
            try
            {
                typeof(VitaCOM).GetMethod("help_" + char.ToUpper(command[0]) + command.Substring(1), BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null);
            }
            catch
            {
                help();
            }
        }

        private static void help_Connect()
        {
            PrintHelp("Connects to a PSM compatible device.",
                "CONNECT <DEVICE ID>",
                new string[] { "<DEVICE ID>" },
                new string[] { "The ID of the device to connect to." },
                "Use LIST for a list of devices and IDs.",
                new string[] { "CONNECT 0" });
        }

        private static void help_Details()
        {
            PrintHelp("Displays detailed information about a PSM compatible device.",
                "DETAILS <DEVICE ID>",
                new string[] { "<DEVICE ID>" },
                new string[] { "The ID of the device to display detailed information." },
                "Use LIST for a list of devices and IDs.",
                new string[] { "DETAILS 0" });
        }

        private static void help_Disconnect()
        {
            PrintHelp("Disconnects from the currently connected device.",
                "DISCONNECT",
                null,
                null,
                null,
                new string[] { "DISCONNECT" });
        }

        private static void help_Exit()
        {
            PrintHelp("Exits the VitaCOM command interpreter.",
                "EXIT",
                null,
                null,
                null,
                new string[] { "EXIT" });
        }

        private static void help_Help()
        {
            PrintHelp("Displays a list of the available commands or detailed help information for a specified command.",
                "HELP [<COMMAND>]",
                new string[] { "[<COMMAND>]" },
                new string[] { "The command for which to display detail help." },
                "If no command is specified, HELP will display all possible commands.",
                new string[] { "HELP", "HELP DETAILS" });
        }

        private static void help_Kill()
        {
            PrintHelp("Kills the PlayStation Mobile application on the connected device.",
                "KILL",
                null,
                null,
                null,
                new string[] { "KILL" });
        }

        private static void help_Launch()
        {
            PrintHelp("Launches an application on the connected device.",
                "LAUNCH <APP NAME> [<ARGUMENTS>] [-D] [-P] [-C] [-E]",
                new string[] { "<APP NAME>", "[<ARGUMENTS>]", "[-D]", "[-P]", "[-C]", "[-E]" },
                new string[] { "The name of the application to launch.", "Arguments for the application to launch.", "Enable debug mode.", "Enable profile mode.", "Keep device connection.", "Display PSM application output. [EXPERIMENTAL] [FORCES -C]" },
                "Toggles are always placed at the end of the line.",
                new string[] { "LAUNCH SampleApp", "LAUNCH SampleApp -P -E" });
        }

        private static void help_List()
        {
            PrintHelp("Displays a list of PSM compatible devices connected to the computer.",
                "LIST",
                null,
                null,
                null,
                new string[] { "LIST" });
        }

        private static void help_Pack()
        {
            PrintHelp("Packs a folder into a .PSMPAC (PK-Zip) archive.",
                "PACK <FOLDER> <OUTPUT>",
                new string[] { "<FOLDER>", "<OUTPUT>" },
                new string[] { "The folder that contains the pssapp.exe file.", "The output .PSMPAC file." },
                null,
                new string[] { "PACK C:\\PSM_Dev\\SampleApp-unsigned\\ C:\\PSM_Dev\\SampleApp.psspac" });
        }

        private static void help_Uninstall()
        {
            PrintHelp("Uninstalls an application on the connected device.",
                "UNINSTALL <APP NAME>",
                new string[] { "<APP NAME>" },
                new string[] { "The app to uninstall." },
                null,
                new string[] { "UNINSTALL SampleApp" });
        }

        private static void help_Upload()
        {
            PrintHelp("Uploads and installs an application on the connected device.",
                "UPLOAD <PSMPAC> <APP NAME>",
                new string[] { "<PSMPAC>", "<APP NAME>" },
                new string[] { "The path to the .PSMPAC to upload.", "The desired name to be displayed on the device." },
                "If the app already exists on the device, it will be overwritten.",
                new string[] { "UPLOAD C:\\PSM_Dev\\SampleApp.psspac SampleApp" });
        }
    }
}